package persistence

import (
	"gorm.io/gorm"
	"tools.hezhuyun/checker/domain/entity"
)

type FolderRepo struct {
	db *gorm.DB
}

func NewFolderRepository(db *gorm.DB) *FolderRepo {
	return &FolderRepo{db}
}

func (repo *FolderRepo) GetFolder(id uint64) (*entity.Folder, error) {
	var folder *entity.Folder
	result := repo.db.Where("ID = ?", id).First(&folder)
	return folder, result.Error
}

// 分层级拿到子目录, 和文件信息
func (repo *FolderRepo) GetFoldersByCode(innerCode string) ([]entity.Folder, error) {
	var folders []entity.Folder
	result := repo.db.Where("InnerCode = ?", innerCode).Find(&folders)
	return folders, result.Error
}
